﻿-- Relacion entre catalogo de red con actual e historico

IF NOT EXISTS (SELECT * FROM esf_sso.BasicReferenceType WHERE Name = 'Monitored Directories SubCategories')
BEGIN
	SET IDENTITY_INSERT esf_sso.BasicReferenceType ON

	INSERT INTO esf_sso.BasicReferenceType (ID, Name)
	VALUES (3001, 'Monitored Directories SubCategories')

	SET IDENTITY_INSERT esf_sso.BasicReferenceType OFF
END


-- Subcategorias para Salud Total

INSERT INTO esf_sso.BasicReference (BasicReferenceTypeID, Code, Name, IsEnabled, CreationDateTime)
SELECT 3001, 'Historico', 'Historico', 1, GETDATE ()
UNION
SELECT 3001, 'Actual', 'Actual', 1, GETDATE ()


-- select * from esf_sso.basicreference where basicreferencetypeid = 3000

INSERT INTO 
	[esf_sso].[TreeBasicReference]
		([ParentBasicReferenceID]
		,[BasicReferenceID]
		,[Value])
SELECT
	(SELECT ID FROM esf_sso.BasicReference WHERE Code = 'SaludTotal_Red_Mix' AND BasicReferenceTypeID = 3000)
	,(SELECT ID FROM esf_sso.BasicReference WHERE Code = 'Historico' AND BasicReferenceTypeID = 3001)
	,NULL
UNION
SELECT
	(SELECT ID FROM esf_sso.BasicReference WHERE Code = 'SaludTotal_Red_Mix' AND BasicReferenceTypeID = 3000)
	,(SELECT ID FROM esf_sso.BasicReference WHERE Code = 'Actual' AND BasicReferenceTypeID = 3001)
	,NULL	
SELECT
	(SELECT ID FROM esf_sso.BasicReference WHERE Code = 'SaludTotal_Red' AND BasicReferenceTypeID = 3000)
	,(SELECT ID FROM esf_sso.BasicReference WHERE Code = 'Historico' AND BasicReferenceTypeID = 3001)
	,NULL
UNION
SELECT
	(SELECT ID FROM esf_sso.BasicReference WHERE Code = 'SaludTotal_Red' AND BasicReferenceTypeID = 3000)
	,(SELECT ID FROM esf_sso.BasicReference WHERE Code = 'Actual' AND BasicReferenceTypeID = 3001)
	,NULL	


